<?php

function recursive_create_category_and_keyword($category_infos, $parent_category = null) {/*{{{*/

    foreach ($category_infos as $key => $value) {

        if (is_numeric($key)) {

            keyword::create($parent_category, $value);
        } else {

            $category = category::create($key);

            if ($parent_category instanceof category) {

                $category->parent_category = $parent_category;
            }

            recursive_create_category_and_keyword($value, $category);
        }
    }
};/*}}}*/

command('seed:data-init', '数据初始化', function ()
{/*{{{*/
    unit_of_work(function () {

        $subjects = dao('subject')->find_all();
        foreach ($subjects as $subject) {
            $subject->delete();
            echo '删除 subject '.$subject->id."\n";
        }

        $categories = dao('category')->find_all();
        foreach ($categories as $category) {
            $category->delete();
            echo '删除 category '.$category->id."\n";
        }

        $keywords = dao('keyword')->find_all();
        foreach ($keywords as $keyword) {
            $keyword->delete();
            echo '删除 keyword '.$keyword->id."\n";
        }

        $subject_names = [/*{{{*/
            '其它',
            '柚子',
            '苹果',
            '石榴',
            '草莓',
            '梨',
            '香蕉',
            '葡萄',
            '水果',
            '榴莲',
            '百果园',
            '桃子',
            '橘子',
            '猕猴桃',
            '橙子',
            '梨子',
            '枣子',
            '水蜜桃',
            '椰子',
            '芒果',
            '奇异果',
            '菠萝蜜',
            '火龙果',
            '冬枣',
            '瓜',
            '哈密瓜',
            '牛油果',
            '菠萝',
            '柚',
            '牛顿苹果',
            '蜜瓜',
            '龙眼',
            '沙漠蜜瓜',
            '澳柑',
            '沃柑',
            '服务',
            '柿子',
            '山竹',
            '提子',
            '外卖',
            '巨峰葡萄',
            '枣',
            '李子',
            '椰青',
            '百香果',
            '枇杷',
            '包装',
            '黄金果',
            '西梅',
            '泰国龙眼',
            '桂圆',
            '蓝莓',
            '退款',
            '哈蜜瓜',
            '巨峰',
            '蜜桔',
            '小苹果',
        ]; /*}}}*/

        foreach ($subject_names as $subject_name) {

            subject::create($subject_name);
        }

        $category_infos = [/*{{{*/
            '系统问题' => [
                'APP系统问题' => [
                    '商城系统异常' => [
                    ],
                    'ERP系统异常' => [
                    ],
                    '财务延误' => [
                    ],
                    '系统缺陷' => [
                    ],
                    '定位' => [
                    ],
                    '操作复杂' => [
                    ],
                    '后台流程复杂' => [
                    ],
                ],
                '三方系统问题' => [
                    '京东到家' => [
                    ],
                    '百度外卖' => [
                    ],
                    '饿了吗' => [
                    ],
                    '美团' => [
                    ],
                    '天猫商城' => [
                    ],
                    '淘宝到家' => [
                    ],
                ],
                '一体化系统' => [
                    '一体化系统异常' => [
                    ],
                    '一体化系统缺陷' => [
                    ],
                ],
                '收银系统' => [
                    '收银系统异常' => [
                    ],
                    '收银系统缺陷' => [
                    ],
                ],
                '网络问题' => [
                    '门店网络不稳定' => [
                    ],
                    '门店无网络' => [
                    ],
                ],
            ],
            '运营问题' => [
                '价格' => [
                    '价格贵' => [
                    ],
                    'APP标价错' => [
                    ],
                    '三方平台标价错' => [
                    ],
                    '价格变化' => [
                    ],
                ],
                '商品描述' => [
                    'APP图文不符' => [
                    ],
                    '三方平台图文不符' => [
                    ],
                    'APP规格描述' => [
                    ],
                    '三方平台规格描述' => [
                    ],
                    '其他平台规格描述' => [
                    ],
                ],
                '活动规则' => [
                    'APP活动' => [
                    ],
                    '三方平台活动' => [
                    ],
                    '其他平台活动' => [
                    ],
                    '门店活动' => [
                    ],
                ],
                '运营其他' => [
                    '收银小票等其他运营限制提供的服务' => [
                    ],
                ],
            ],
            '鲜度' => [
                '变味' => [
                ],
                '变色' => [
                ],
                '发霉' => [
                ],
                '过熟' => [
                ],
                '腐烂' => [
                ],
                '果损' => [
                    '碰伤、压伤' => [
                    ],
                ],
                '失水' => [
                ],
                '掉粒' => [
                ],
                '不熟' => [
                ],
                '裂口' => [
                ],
                '虫眼' => [
                ],
                '鲜度其他' => [
                ],
                '过期' => [
                ],
            ],
            '口感' => [
                '不甜' => [
                ],
                '酸' => [
                ],
                '发涩' => [
                ],
                '苦' => [
                ],
                '咸' => [
                ],
                '味道不正' => [
                ],
                '口感其他' => [
                ],
            ],
            '果型' => [
                '长的不好看' => [
                ],
                '过大过小' => [
                ],
                '有疤' => [
                ],
                '果面脏' => [
                ],
                '皮厚肉少' => [
                ],
                '来货问题' => [
                ],
            ],
            '内部变质' => [
                '变质' => [
                ],
                '长虫' => [
                ],
                '内部变质其他' => [
                ],
            ],
            '商品' => [
                '商品包装' => [
                    '顾客主观不满' => [
                    ],
                ],
                '果品脏' => [
                ],
            ],
            '配货问题' => [
                '门店备货超时' => [
                ],
                '门店未备货' => [
                ],
                '门店提前备货抛单' => [
                ],
                '门店缺货' => [
                    '门店下架未及时' => [
                    ],
                    '出货品质未达标' => [
                    ],
                ],
                '门店少称' => [
                    '私自调整果品重量' => [
                    ],
                    '重量不足' => [
                    ],
                ],
                '门店漏配' => [
                    '门店漏发' => [
                    ],
                ],
                '门店错配' => [
                    '配错果品' => [
                    ],
                ],
                '门店包装' => [
                    '未按线上要求包装出货' => [
                    ],
                ],
                '包装内异物' => [
                ],
            ],
            '自营配送' => [
                '已送达未收到' => [
                    '虚假回单' => [
                    ],
                ],
                '自营配送超时' => [
                    '拒送' => [
                    ],
                    '送货超时' => [
                    ],
                    '错地址' => [
                    ],
                    '联系不上用户导致未能送货' => [
                    ],
                    '超时改自配' => [
                    ],
                    '错货' => [
                    ],
                ],
                '已送达未收到' => [
                    '非本人签收' => [
                    ],
                ],
                '自营配送态度' => [
                    '配送人员态度' => [
                    ],
                    '其他' => [
                    ],
                ],
                '自营配送货损' => [
                    '果品损伤' => [
                    ],
                    '包装损伤' => [
                    ],
                ],
            ],
            '三方配送' => [
                '已送达未收到' => [
                    '虚假回单' => [
                    ],
                    '非本人签收' => [
                    ],
                ],
                '三方配送超时' => [
                    '拒送' => [
                    ],
                    '送货超时' => [
                    ],
                    '错地址' => [
                    ],
                    '联系不上用户导致未能送货' => [
                    ],
                    '超时改自配' => [
                    ],
                    '错货' => [
                    ],
                ],
                '已送达未收到' => [
                ],
                '三方配送态度' => [
                    '配送人员态度' => [
                    ],
                    '其他' => [
                    ],
                ],
                '三方配送货损' => [
                    '果品损伤' => [
                    ],
                    '包装破损' => [
                    ],
                ],
            ],
            '门店服务' => [
                '门店服务' => [
                    '店员态度' => [
                    ],
                    '门店果品专业知识' => [
                    ],
                    '门店业务错误' => [
                    ],
                    '承诺未兑现' => [
                    ],
                    '门店其他' => [
                    ],
                    '发票问题' => [
                    ],
                    '不看客户备注' => [
                    ],
                    '门店业务操作' => [
                    ],
                    '小票问题' => [
                    ],
                    '门店标价错' => [
                    ],
                    '物料收费' => [
                    ],
                    '门店诚信' => [
                    ],
                    '拆包挑选' => [
                    ],
                    '三无退货' => [
                    ],
                    '试吃问题' => [
                    ],
                    '门店退款' => [
                    ],
                    '音乐扰民' => [
                    ],
                ],
                '洗切服务' => [
                    '洗切' => [
                    ],
                    '打孔' => [
                    ],
                    '剥皮' => [
                    ],
                    '叉子、牙签' => [
                    ],
                    '吸管' => [
                    ],
                ],
                '门店服务' => [
                    '门店退款' => [
                    ],
                ],
            ],
            '客服服务' => [
                '客服服务' => [
                    '客服态度' => [
                    ],
                    '客服果品专业知识' => [
                    ],
                    '客服业务错误' => [
                    ],
                    '承诺未兑现' => [
                    ],
                    '客服其他' => [
                    ],
                ],
            ],
            '安全问题' => [
                '人身安全' => [
                    '食用果品身体不适' => [
                    ],
                    '送货员配送中人身安全' => [
                    ],
                    '配送引发顾客人身安全' => [
                    ],
                ],
                '果品安全' => [
                    '果品有异味' => [
                    ],
                    '果品非正常变化' => [
                    ],
                    '果蜡' => [
                    ],
                    '其他' => [
                    ],
                ],
                '资金安全' => [
                    '账户余额异常' => [
                    ],
                    '消费异常' => [
                    ],
                ],
            ],
            '售后' => [
                '售后' => [
                    '售后' => [
                    ],
                ],
            ],
            '大仓配货问题' => [
                '备货问题' => [
                    '大仓未备货' => [
                    ],
                    '大仓提前备货抛单' => [
                    ],
                ],
                '大仓缺货' => [
                    '大仓下架未及时' => [
                    ],
                    '出货品质未达标' => [
                    ],
                ],
                '大仓少称' => [
                    '私自调整果品重量' => [
                    ],
                    '重量不足' => [
                    ],
                ],
                '大仓漏配' => [
                    '大仓漏发' => [
                    ],
                ],
                '大仓错配' => [
                    '配错果品' => [
                    ],
                ],
                '大仓包装' => [
                    '未按线上要求包装出货' => [
                    ],
                    '包装内异物' => [
                    ],
                ],
                '大仓服务' => [
                    '大仓业务错误' => [
                    ],
                    '票据' => [
                    ],
                    '不看客户备注' => [
                    ],
                ],
            ],
            '会员问题' => [
                '会员信息' => [
                ],
                '消费记录' => [
                ],
                '果粒值' => [
                ],
                '积分' => [
                ],
                '优惠券' => [
                ],
                '异常退款解锁' => [
                ],
            ],
            '设备问题' => [
                '门店设备' => [
                    '信息设备问题' => [
                    ],
                    '工程设备问题' => [
                    ],
                ],
            ],
            '好吃卡问题' => [
                '纸质卡' => [
                    '挂失问题' => [
                    ],
                    '使用问题' => [
                    ],
                ],
            ],
            '好吃卡问题' => [
                '电子卡' => [
                    '挂失问题' => [
                    ],
                    '使用问题' => [
                    ],
                ],
            ],
            '投诉店长' => [
                '员工投诉店长' => [
                ],
            ],
            '投诉总部人员' => [
                '员工投诉总部人员' => [
                ],
                '顾客投诉总部人员' => [
                ],
            ],
        ];/*}}}*/

        recursive_create_category_and_keyword($category_infos);
    });
});/*}}}*/
